<# # It is recommended to test the script on a local machine for its purpose and effects. # ManageEngine Endpoint Central will not be responsible for any # damage/loss to the data/setup based on the behavior of the script. # Description: Script is designed to delete the degraded local user account # Configuration Type - COMPUTER #> # Get all local user accounts $users = Get-WmiObject -Class Win32_UserAccount | Where-Object { $_.LocalAccount -eq $true } # Filter for degraded (disabled or locked) users $degradedUsers = $users | Where-Object { $_.Disabled -eq $true -or $_.LockedOut -eq $true } # Loop through each degraded user and remove using net user command foreach ($user in $degradedUsers) { try { $userName = $user.Name Write-Host "Removing user: $userName" # Use net user command to delete the user account net user $userName /delete Write-Host "User $userName has been removed." } catch { Write-Host "Error removing user $($user.Name): $_" } }